package cn.cable.monitor.admin.trigger.listener;

import cn.cable.monitor.admin.domain.service.ILogAnalyticalService;
import cn.cable.monitor.sdk.model.LogMessage;
import com.alibaba.fastjson.JSON;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.redisson.api.listener.MessageListener;
import org.springframework.stereotype.Component;

/**
 * 监听日志控制器
 * @author hsj
 * @date 2024/7/18 14:15
 */
@Slf4j
@Component
public class MonitorLogListener implements MessageListener<LogMessage> {

	@Resource
	private ILogAnalyticalService logAnalyticalService;


	@Override
	public void onMessage(CharSequence charSequence, LogMessage logMessage) {

		try {
			log.info("监听监控日志消息,解析存储:{}", JSON.toJSONString(logMessage));
			logAnalyticalService.doAnalytical(logMessage.getSystemName(),logMessage.getClassName(),logMessage.getMethodName(),logMessage.getLogList());
		} catch (Exception e) {
			log.error("监听监控日志消息,解析失败:{}", JSON.toJSONString(logMessage), e);
		}
	}

}
